package com.atguigu.atcrowdfunding.controller;

import com.atguigu.atcrowdfunding.bean.TPermission;
import com.atguigu.atcrowdfunding.service.TPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class TPermissionController {
    @Autowired
    TPermissionService permissionService;


    @ResponseBody
    @RequestMapping("/permission/doAdd")
    public String doAdd(TPermission permission){
        permissionService.saveTPermission(permission);
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/permission/loadTree")
    public List<TPermission> loadTree(TPermission permission){

        return permissionService.listPermissionAllTree(permission);
    }

    @RequestMapping("/permission/index")
    public String index(){

        return "permission/index";
    }

    @ResponseBody
    @RequestMapping("/permission/getPermissionById")
    public TPermission getPermissionById(Integer id){
        TPermission permission = permissionService.getPermissionById(id);
        return permission;
    }


    @ResponseBody
    @RequestMapping("/permission/doDelete")
    public String doDelete(Integer id){
        permissionService.deletePermission(id);
        return "ok";
    }
}
